<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    /* 
      如果一个路由组件中有一个router-view
      那么我们如果想要给router-view上渲染内容，直接在对应路由组件的那个路由配置下写上children选项，
      {
        path: '/parent',
        compoent: parent,
        children: [
          {
            path: 'child1',
            component: child1
          }, {
            path: 'child2',
            component: child2
          }
        ]
      }

      这个child组件就会出现在parent组件中的router-view里，对应的路由为 /parent/child1


      一般情况我们都需要去模拟多页效果
        只在app的组件模板中添加router-view

      我们在单个子页面中有需要去进行相关的切换操作时，就需要使用嵌套路由

      想要在哪个组件中进行切换，那么就找到这个组件的路由配置，然后在路由配置写children配置
    
     */
    const gold = {
      template: `
        <div>金币商城</div>
      `
    }

    const nav = {
      template: `
        <div>
          <router-view></router-view>
          <nav>
            <router-link to="/nav/index">首页</router-link>
            <router-link to="/nav/discover">发现</router-link>
            <router-link to="/nav/order">订单</router-link>
            <router-link to="/nav/profile">我的</router-link>

          </nav>
        </div>
      `
    }

    const demo = {
      template: `
        <div>demo</div>
      `
    }

    const index = {
      template: `
        <div>首页</div>
      `
    }

    const discover = {
      template: `
        <div>发现</div>
      `
    }
    
    const order = {
      template: `
        <div>order</div>
      `
    }

    const profile = {
      template: `
        <div>
          我的
          <router-link to="/gold">金币商城入口</router-link>
        </div>
      `
    }

    const routes = [
      {
        path: '/gold',
        component: gold
      }, {
        path: '/nav',
        component: nav,
        children: [
          {
            path: 'demo',
            component: demo
          }, {
            path: 'index', 
            component: index
          }, {
            path: 'discover',
            component: discover
          }, {
            path: 'order', 
            component: order
          }, {
            path: 'profile',
            component: profile
          }
        ]
      }, /* {
        path: '/nav/demo',
        component: demo
      } */
    ]

    const router = new VueRouter({
      routes
    })

    const app = new Vue({
      el: '#app',
      router
    })
  
  </script>
</body>
</html>